package zc.cennavi.taxi;

import zc.cennavi.taxi.util.LogCat;
import zc.cennavi.taxi.util.SettingSharePreference;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class FirstSettingActivity extends Activity {
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		LogCat.i("....FirstSettingActivity.onCreate(");
		setContentView(R.layout.first_setting);

		init();
	}

	private TextView layout_shanghai = null;
	private TextView layout_beijing = null;
	private TextView txt_shanghai = null;
	private TextView txt_beijing = null;
	private Button sure_btn = null;

	private void findViewByIds() {
		layout_shanghai = (TextView) findViewById(R.id.layout_shanghai);
		layout_beijing = (TextView) findViewById(R.id.layout_beijing);
		txt_shanghai = (TextView) findViewById(R.id.txt_shanghai);
		txt_beijing = (TextView) findViewById(R.id.txt_beijing);
		sure_btn = (Button) findViewById(R.id.sure_btn);

		layout_shanghai.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				txt_shanghai.setVisibility(View.VISIBLE);
				txt_beijing.setVisibility(View.INVISIBLE);
				mSettingSharePreference.checkShangHai();
			}
		});
		layout_beijing.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				txt_beijing.setVisibility(View.VISIBLE);
				txt_shanghai.setVisibility(View.INVISIBLE);
				mSettingSharePreference.checkBeijing();
			}
		});

		sure_btn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				// open TaxiIndexActivity

				Intent intent = new Intent(FirstSettingActivity.this, TaxiIndexActivity.class);
				startActivity(intent);
				finish();

			}
		});
	}

	private Context mContext = FirstSettingActivity.this;
	private SettingSharePreference mSettingSharePreference = null;

	private void init() {
		mSettingSharePreference = new SettingSharePreference(mContext);
		findViewByIds();

		// show value
		if (mSettingSharePreference.isBeiJing()) {
			txt_beijing.setVisibility(View.VISIBLE);
			txt_shanghai.setVisibility(View.INVISIBLE);
		} else {
			txt_shanghai.setVisibility(View.VISIBLE);
			txt_beijing.setVisibility(View.INVISIBLE);
		}

	}
}